const express = require('express')
const app = express()
const port = 3000

var mysql = require('mysql');
var pool  = mysql.createPool({
  connectionLimit : 10,
  host            : 'localhost',
  user            : 'root',
  password        : '12345678',
  database        : 'students'
});


app.get('/data', (req, res) => {

  pool.query('SELECT * FROM students.user;', function (error, results, fields) {
    if (error) throw error;
    res.json(results)
  });

})

app.post('/data', (req, res) => {
  let data = {name: 'jack1', age: 19, sex: 1, password: 'hahahh', cid: 1}
  pool.query(`insert into students.user set ?;`, data, function(error, results) {
    console.log(results);
    res.send('ok')
  })
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))